<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="expires" content="0">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<title></title>
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
		<style> .productFile { padding: 0.33rem; background: #fff; }  .productFile p { color: #666; margin-bottom: 0.42rem; }  .file1 { width: 60%; } .mui-bar-nav ~ .mui-content .mui-pull-top-pocket{top:50px !important; }</style>
	</head>
	<body>
		<div class="mui-content" style="padding: 0.24rem 0.24rem 0 0.24rem;">
			<div id="content">
				<div id="refresh">
					<div class="productFile" id="productFile">
					</div>
					<div class="historyList">
						<p>历史记录</p>
						<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
							<div class="mui-scroll">
								<!--数据列表-->
								<ul class="mui-table-view mui-table-view-chevron historyUi">
									
								</ul>
							</div>
						</div>
					</div>
				</div>
			</div>
			
		</div> 
		
	<script src="../../js/resize.js"></script>
	<script src="../../js/mui.min.js"></script> 
	<script src="../../js/ajaxFun.js"></script>
	 <script>
	 	var data = {
			pageNo: 1,
			pageSize: 10,
			productNo: ''
		};
		var table = document.body.querySelector('.historyUi');
		var pfile=document.getElementById("productFile");
		(function($, doc) {
			$.plusReady(function() {
				var currentview=plus.webview.currentWebview();
				var productNo=currentview.productNo
				if(!productNo){
					plus.nativeUI.alert('产品不存在！', function() {
								$.back();
					}, '提示', '确定');
				}else{
					data.productNo=productNo;
					/*异步获取产品信息*/
					var url = baseUrl + 'product/get/by/productno.do';
					ajaxFun.postFun(url, {
						productNo: productNo
					}, '', function(dataInfo, params) {
						var html = formPinfoHtml(dataInfo.data);
						pfile.innerHTML = html;
					});
				}
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							 callback: pulldownRefresh
						},
						up: { 
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				
			})
		}(mui, document))
		
		if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 100);

				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
			
	function pulldownRefresh() {
			setTimeout(function() {
					mui('#pullrefresh').pullRefresh().scrollTo(0,0,100);
					var url = baseUrl + 'history/get/by/traderid.do';
					data.pageNo=1;table.innerHTML='';
					mui('#pullrefresh').pullRefresh().refresh(true);
					ajaxFun.postFun(url,data,'',formList);		 
			}, 100);	
	}
			
		function pullupRefresh() { 
			setTimeout(function() {
				var url = baseUrl + 'history/get/by/traderid.do';
				ajaxFun.postFun(url,data,'',formList);
			}, 100);	
		}
		
	 
		var total = 0;
		function formList(datalist, params) {
			setTimeout(function() {
				data.pageNo++;
				var list = datalist.data.dataList ? datalist.data.dataList : [];
				total = datalist.data.total >= 0 ? datalist.data.total : total;
				if(list.length > 0) {
					for(var i = 0, len = list.length; i < len; i++) {
						var temp = list[i];
						var li = document.createElement('li');
						li.className = 'historyItem';
						var html = '';
						var opType = temp.opType == 1 ? '出库' : '入库';
						var ss=temp.opType == 1 ? '去向' : '来源';
						temp.mobile=temp.mobile?temp.mobile:'';
						html += '<p class="opeate">' + opType + '</p>' +
							'<p>操作时间：' + temp.updateTime + '</p>' +
							'<p>'+ss+'：' + temp.traderName + ' ' + temp.mobile + '</p>';
						li.innerHTML = html;
						table.appendChild(li);
					}
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					var liLen = document.querySelectorAll('.historyItem').length;
					if(liLen >= total) {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); //参数为true代表没有更多数据了。
					}
				} else {
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				}

			}, 1500);
		}
		/*生成产品信息HTML*/
		function formPinfoHtml(info) {
			info.productName = info.productName ? info.productName : '';
			info.norms = info.norms ? info.norms : 0;
			info.factoryName = info.factoryName ? info.factoryName : '';
			var html = '<div class="fl file1"> <p>产品名称：' + info.productName + '</p>  <p>产品规格：' + info.norms + '</p> <p>产品单位：箱</p> </div> <div class="fr" style="width:40%;"> <img src="' + routeUrl + info.imgUrl + '" style="width:100%" /> </div> <div class="clearfix"></div> <div> <p>产品产地：' + info.province + info.city + '</p> <p style="margin-bottom:0px;">公司名称：' + info.factoryName + '</p> </div>';
			return html;
		}
	 </script>
	</body>
</html>
